# __author__ = 'panagiotis'


from models import SentimentTransformer

transformer_1 = SentimentTransformer(vectorizer="count", tokenize=False, lemmatize=True)
transformer_2 = SentimentTransformer(vectorizer="tf", tokenize=False, lemmatize=True)
transformer_3 = SentimentTransformer(vectorizer="tfidf", tokenize=False, lemmatize=True)

for v_name, vectorizer in [("Counts", transformer_1), ("Frequencies", transformer_2), ("TFIDF", transformer_3)]:  # 5 min per iteration
    print 50*"-"
    print "Transformer:", v_name,
    t0 = datetime.now()
    X_train = vectorizer.fit_transform(train_review, train_target)  # should I keep a copy?
    X_test = vectorizer.transform(test_review)
    print "vectorizing time", datetime.now() - t0
    for c_name, clf in [("RBF SVC\t", SVC(C=1000, gamma=0.01)),
                      ("Linear SVC\t", LinearSVC(dual=False, tol=1e-3)),
                      ("Naive Bayes", MultinomialNB()),
                      ("Max Entropy", LogisticRegression()),
                      ]:
        t0 = datetime.now()
        clf.fit(X_train, train_target)
        z_test = clf.predict(X_test)

        # results[v_name][c_name].append((
        #                       precision_score(test_target, z_test),
        #                       recall_score(test_target, z_test),
        #                       f1_score(test_target, z_test),))
        print "classifier:", c_name, "\t",
        print "classification time:", datetime.now() - t0, "\t",
        print "precision", precision_score([1 if r > 3 else -1 for r in test_target], [1 if r > 3 else -1 for r in z_test]),
        print "recall", recall_score([1 if r > 3 else -1 for r in test_target], [1 if r > 3 else -1 for r in z_test]),
        print "f-measure:", f1_score([1 if r > 3 else -1 for r in test_target], [1 if r > 3 else -1 for r in z_test])
        print confusion_matrix([1 if r > 3 else -1 for r in test_target], [1 if r > 3 else -1 for r in z_test])
        print 30*"-"

